package com.itheima.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitMQConfig {

    //声明队列
    public final static  String DELETE_QUEUE = "delete_queue";
    public final static  String ADD_QUEUE = "add_queue";

    //声明交换机
    public final static String DELETE_EXCHANGE = "delete_exchange";
    public final static String ADD_EXCHANGE = "add_exchange";

    @Bean(DELETE_QUEUE)
    public Queue DELETE_QUEUE() {
        return QueueBuilder.durable(DELETE_QUEUE).build();
    }

    @Bean(ADD_QUEUE)
    public Queue ADD_QUEUE() {
        return QueueBuilder.durable(ADD_QUEUE).build();
    }

    @Bean(DELETE_EXCHANGE)
    public Exchange DELETE_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(DELETE_EXCHANGE).build();
    }

    @Bean(ADD_EXCHANGE)
    public Exchange ADD_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(ADD_EXCHANGE).build();
    }

    //将交换机和队列绑定
    @Bean
    public Binding DELETE_EXCHANGE_QUEUE (@Qualifier(DELETE_EXCHANGE) Exchange exchange,@Qualifier(DELETE_QUEUE) Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }

    @Bean
    public Binding ADD_EXCHANGE_QUEUE (@Qualifier(ADD_EXCHANGE) Exchange exchange,@Qualifier(ADD_QUEUE) Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }
}
